package com.ljkj.cordial.chat.bean;

import com.ljkj.cordial.chat.dao.ChatTableBean;
import com.ljkj.cordial.chat.util.AlbumManageUtil;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 聊天ChatTableBean并用
 */
public class ChatTableUnit implements Serializable, Cloneable {
    private static final long serialVersionUID = -5801421772391486916L;
    public final static int SEND = 0;
    public final static int RECEIVE = 1;
    public final static int SEND_ING = 0;
    public final static int SEND_SUCCESS = 1;
    public final static int SEND_FAIL = 2;
    public final static int UNREAD = 0;
    public final static int READED = 1;
    public final static int UNLISTEN = 1;
    public final static int LISTENED = 0;
    private Long id;
    /**
     * 单聊(Canstants.SINGLE_CHAT)、群聊
     */
    private int fromType;
    private String groupId;
    /**
     * 群类别注册群游客群
     */
    private String groupType;
    /**
     * friendId,memberId
     */
    private String targetFileId;
    private String targetId;
    private String targetName;
    private String targetType;
    private String nickName;
    private String alias;
    private String chatAvatarUrl;
    private String chatAvatarPath;
    private String chatAvatarId;
    private int chatType;
    private int chatUnRead;
    private long historyTime;
    private long msgTime;
    private String textMsg;
    private String fileUrl;
    private String thumbPath;
    private long fileLength;
    private String albumId;
    private int sendType;//0发送者1接收者
    private String msgId;
    private String loginUserId;
    private String chatName;
    private boolean startReadFinish;//是否开启阅后即焚
    private long readFinishTime;////阅后即焚时间s
    private int sendState;//0发送中1发送成功2发送失败
    private int voiceListen = UNLISTEN;
    private Long relateId;
    private String atelIds;
    private boolean isChecked;//多选框状态
    private boolean isVisible;//是否显示多选框

    public ChatTableUnit(Long id, int fromType, String groupId, String groupType, String targetFileId, String targetId, String targetName, String targetType, String nickName, String alias, String chatAvatarUrl, String chatAvatarPath, String chatAvatarId, int chatType, int chatUnRead, long historyTime, long msgTime, String textMsg, String fileUrl, String thumbPath, long fileLength, String albumId, int sendType, String msgId, String loginUserId, String chatName, boolean startReadFinish, long readFinishTime, int sendState, int voiceListen, Long relateId, String atelIds, boolean isChecked, boolean isVisible) {
        this.id = id;
        this.fromType = fromType;
        this.groupId = groupId;
        this.groupType = groupType;
        this.targetFileId = targetFileId;
        this.targetId = targetId;
        this.targetName = targetName;
        this.targetType = targetType;
        this.nickName = nickName;
        this.alias = alias;
        this.chatAvatarUrl = chatAvatarUrl;
        this.chatAvatarPath = chatAvatarPath;
        this.chatAvatarId = chatAvatarId;
        this.chatType = chatType;
        this.chatUnRead = chatUnRead;
        this.historyTime = historyTime;
        this.msgTime = msgTime;
        this.textMsg = textMsg;
        this.fileUrl = fileUrl;
        this.thumbPath = thumbPath;
        this.fileLength = fileLength;
        this.albumId = albumId;
        this.sendType = sendType;
        this.msgId = msgId;
        this.loginUserId = loginUserId;
        this.chatName = chatName;
        this.startReadFinish = startReadFinish;
        this.readFinishTime = readFinishTime;
        this.sendState = sendState;
        this.voiceListen = voiceListen;
        this.relateId = relateId;
        this.atelIds = atelIds;
        this.isChecked = isChecked;
        this.isVisible = isVisible;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public int getFromType() {
        return fromType;
    }

    public void setFromType(int fromType) {
        this.fromType = fromType;
    }

    public String getGroupId() {
        return groupId;
    }

    public void setGroupId(String groupId) {
        this.groupId = groupId;
    }

    public String getGroupType() {
        return groupType;
    }

    public void setGroupType(String groupType) {
        this.groupType = groupType;
    }

    public String getTargetFileId() {
        return targetFileId;
    }

    public void setTargetFileId(String targetFileId) {
        this.targetFileId = targetFileId;
    }

    public String getTargetId() {
        return targetId;
    }

    public void setTargetId(String targetId) {
        this.targetId = targetId;
    }

    public String getTargetName() {
        return targetName;
    }

    public void setTargetName(String targetName) {
        this.targetName = targetName;
    }

    public String getTargetType() {
        return targetType;
    }

    public void setTargetType(String targetType) {
        this.targetType = targetType;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getAlias() {
        return alias;
    }

    public void setAlias(String alias) {
        this.alias = alias;
    }

    public String getChatAvatarUrl() {
        return chatAvatarUrl;
    }

    public void setChatAvatarUrl(String chatAvatarUrl) {
        this.chatAvatarUrl = chatAvatarUrl;
    }

    public String getChatAvatarPath() {
        return chatAvatarPath;
    }

    public void setChatAvatarPath(String chatAvatarPath) {
        this.chatAvatarPath = chatAvatarPath;
    }

    public String getChatAvatarId() {
        return chatAvatarId;
    }

    public void setChatAvatarId(String chatAvatarId) {
        this.chatAvatarId = chatAvatarId;
    }

    public int getChatType() {
        return chatType;
    }

    public void setChatType(int chatType) {
        this.chatType = chatType;
    }

    public int getChatUnRead() {
        return chatUnRead;
    }

    public void setChatUnRead(int chatUnRead) {
        this.chatUnRead = chatUnRead;
    }

    public long getHistoryTime() {
        return historyTime;
    }

    public void setHistoryTime(long historyTime) {
        this.historyTime = historyTime;
    }

    public long getMsgTime() {
        return msgTime;
    }

    public void setMsgTime(long msgTime) {
        this.msgTime = msgTime;
    }

    public String getTextMsg() {
        return textMsg;
    }

    public void setTextMsg(String textMsg) {
        this.textMsg = textMsg;
    }

    public String getFileUrl() {
        return fileUrl;
    }

    public void setFileUrl(String fileUrl) {
        this.fileUrl = fileUrl;
    }

    public String getThumbPath() {
        return thumbPath;
    }

    public void setThumbPath(String thumbPath) {
        this.thumbPath = thumbPath;
    }

    public long getFileLength() {
        return fileLength;
    }

    public void setFileLength(long fileLength) {
        this.fileLength = fileLength;
    }

    public String getAlbumId() {
        return albumId;
    }

    public void setAlbumId(String albumId) {
        this.albumId = albumId;
    }

    public int getSendType() {
        return sendType;
    }

    public void setSendType(int sendType) {
        this.sendType = sendType;
    }

    public String getMsgId() {
        return msgId;
    }

    public void setMsgId(String msgId) {
        this.msgId = msgId;
    }

    public String getLoginUserId() {
        return loginUserId;
    }

    public void setLoginUserId(String loginUserId) {
        this.loginUserId = loginUserId;
    }

    public String getChatName() {
        return chatName;
    }

    public void setChatName(String chatName) {
        this.chatName = chatName;
    }

    public boolean isStartReadFinish() {
        return startReadFinish;
    }

    public void setStartReadFinish(boolean startReadFinish) {
        this.startReadFinish = startReadFinish;
    }

    public long getReadFinishTime() {
        return readFinishTime;
    }

    public void setReadFinishTime(long readFinishTime) {
        this.readFinishTime = readFinishTime;
    }

    public int getSendState() {
        return sendState;
    }

    public void setSendState(int sendState) {
        this.sendState = sendState;
    }

    public int getVoiceListen() {
        return voiceListen;
    }

    public void setVoiceListen(int voiceListen) {
        this.voiceListen = voiceListen;
    }

    public Long getRelateId() {
        return relateId;
    }

    public void setRelateId(Long relateId) {
        this.relateId = relateId;
    }

    public String getAtelIds() {
        return atelIds;
    }

    public void setAtelIds(String atelIds) {
        this.atelIds = atelIds;
    }

    public boolean isChecked() {
        return isChecked;
    }

    public void setChecked(boolean checked) {
        isChecked = checked;
    }

    public boolean isVisible() {
        return isVisible;
    }

    public void setVisible(boolean visible) {
        isVisible = visible;
    }

    public static ChatTableUnit copy(ChatTableBean c) {
        return new ChatTableUnit(c.getId(),
                c.getFromType(),
                c.getGroupId(),
                c.getGroupType(),
                c.getTargetFileId(),
                c.getTargetId(),
                c.getTargetName(),
                c.getTargetType(),
                c.getNickName(),
                c.getAlias(),
                c.getChatAvatarUrl(),
                c.getChatAvatarPath(),
                c.getChatAvatarId(),
                c.getChatType(),
                c.getChatUnRead(),
                c.getHistoryTime(),
                c.getMsgTime(),
                c.getTextMsg(),
                c.getFileUrl(),
                c.getThumbPath(),
                c.getFileLength(),
                c.getAlbumId(),
                c.getSendType(),
                c.getMsgId(),
                c.getLoginUserId(),
                c.getChatName(),
                c.getStartReadFinish(),
                c.getReadFinishTime(),
                c.getSendState(),
                c.getVoiceListen(),
                c.getRelateId(),
                c.getAtelIds(),
                c.isChecked(),
                c.isVisible());
    }



    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }

    public static List<ChatTableUnit> copys(List<ChatTableBean> c) {
        List<ChatTableUnit> list = new ArrayList<>();
        for (ChatTableBean bean : c) {
            list.add(copy(bean));
        }
        return list;
    }

    public long getReadFinishSpaceTime() {
        long s = (getMsgTime() + getReadFinishTime() * 1000 - System.currentTimeMillis());
//        JLog.e(getStartReadFinish()+"read finish space time"+s);
        return s;
    }

    public String getReadFinishFormatTime() {
//        getReadFinishTime() * 1000
        return AlbumManageUtil.generateTime(getReadFinishSpaceTime());
    }

    public static ChatTableBean getTable(ChatTableUnit unit) {
        return ChatTableBean.getTableFromId(String.valueOf(unit.getId()));
    }
}
